//
// Created by 11510 on 2024/6/25.
//
#include <iostream>
#include <list>

using namespace std;

std::ostream &operator<<(std::ostream &ostr, const std::list<int> &list) {
    for (auto &i: list) {
        ostr << " " << i;
    }
    return ostr;
}

/**
 * 函数对象，自定义类，实现重载运算符比较大小
 */
struct CompareList {
    bool operator()(const int &lhs, const int &rhs) const {
        return lhs > rhs;
    }
};


void test0() {
    list<int> number = {3, 6, 5, 8, 4, 7, 6, -1};
//    升序
//    number.sort(std::less<int>());
//    降序
//    number.sort(std::greater<int>());

//    自定义
    number.sort(CompareList());/* 这里需要传一个对象所以加() */

//    逆置
    number.reverse();
//    去连续重复
    number.unique();


    list<int> number2 = {1, 2, 8, -1, 0};
    number2.sort();

    /**
     * 两个链表merge的时候需要统一排序方式，然后再merge
     * 合并后第二条链表为空
     */
    number.merge(number2);
    for (auto &elem: number) {
        cout << elem << " ";
    }
}

void test1() {

    std::list<int> list1 = {1, 2, 3, 4, 5};
    std::list<int> list2 = {10, 20, 30, 40, 50};

    auto it = list1.begin();
    std::advance(it, 2);

    list1.splice(it, list2);

    std::cout << "list1: " << list1 << "\n";
    std::cout << "list2: " << list2 << "\n";
}








int main() {
    test1();
    return 0;
}